package values.item
{
import flash.errors.IllegalOperationError;
import flash.utils.Dictionary;

public class ItemTemplateValueList
{	
	private static var list:Dictionary = new Dictionary(true); /* ItemTemplateValue */
	
	private static var resources:Dictionary = new Dictionary(true);  /* ResourceItemTemplateValue */
	
	public function get items():Dictionary
	{
		return list;
	}
	
	[Data(type="mapping", 
		   mapping="item", 
		   ref="$@classRef",
		   way="one_to_more",
		   object="flash.utils.Dictionary",
           key="@key")]
	public function set items(value:Dictionary):void
	{
		for each (var item:ItemTemplateValue in value)
		{
            list[item.key] = item;
			if (item.type == "resource")
			{
				resources[item.key] = item;
			}
		}
	}
	
	public static function get resourceList():Dictionary
	{
		return resources;
	}
	
	public static function get itemList():Dictionary
	{
		return list;
	}
	
	public static function getByKey(key:String):ItemTemplateValue
	{
		var item:ItemTemplateValue = list[key];
		if (!item)
		{
			throw new IllegalOperationError("Cannot find <" + key + "> item. Please check data configuration.");
		}
		return item;
	}

}
}